package com.example.day2.busi.login;

import androidx.lifecycle.MutableLiveData;

import com.example.day2.entity.LoginParam;
import com.example.day2.entity.LoginResult;
import com.example.day2.mvvm.base.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class LoginRepo extends BaseRepo {
    public void login(LoginParam loginParam, MutableLiveData<LoginResult> success,MutableLiveData<String> fail){
        apiService.getLogin(loginParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LoginResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LoginResult loginResult) {
                        success.setValue(loginResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
